<template>
  <div>
    <h1>App</h1>
    <div>
      <button @click="Comp = 'News'">新闻</button>
      <button @click="Comp = 'Music'">音乐</button>
      <button @click="Comp = 'Play'">游戏</button>
    </div>

    <!-- 
        有两个生命周期函数可以监听 被keep-alive缓存的组件的 失活和激活状态
          activated：被 keep-alive 缓存的组件激活时调用
          deactivated keep-alive 缓存的组件失活时调用
     -->
    <keep-alive>
      <component :is="Comp"></component>
    </keep-alive>
  </div>
</template>

<script>
import Music from "@/components/Music";
import Play from "@/components/Play";
import News from "@/components/News";
export default {
  name: "App",
  components: {
    Play,
    News,
    Music,
  },
  data() {
    return {
      Comp: "Play",
    };
  },
};
</script>

<style></style>
